package com.itheima.day04;

import java.util.Scanner;

public class Demo{

    public static void main(String[] args) {

        while (true) {
            try {
                double price = getPrice();
                System.out.println("price = " + price);
                break;//结束循环
            }catch (NumberFormatException e){
                //e.printStackTrace();
                System.out.println("价格获取有误，请重新输入一个合法的价格数据！");
            }
        }

        System.out.println("程序结束");
    }


    public static double getPrice() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个价格：");
        String strPrice = sc.next();
        double price = Double.parseDouble(strPrice);//该方法潜在一个 NumberFormatException 异常，是一个运行时异常
        return price;
    }

}